<template>
    <view class="page">
        <block v-if="url.length > 0">
            <web-view :webview-styles="webviewStyles" :src="url"></web-view>
        </block>
    </view>
</template>

<script setup>
import { ref } from 'vue';
import { onLoad, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
import { useConfigStore, useIndexStore } from '@/store/index';
import { storeToRefs } from 'pinia';
import { check_token } from '@/common/utils/check';

const configStore = useConfigStore();
const indexStore = useIndexStore();

const { scene, platform } = storeToRefs(configStore);
const { nowCityCode } = storeToRefs(indexStore);

const url = ref('');
const cityCode = ref('310100');
const webviewStyles = {
    progress: {
        color: '#FF3333'
    }
};

// 分享到好友
onShareAppMessage(() => {
    return {
        title: "开盘日历",
        path: `/pages/tools/calendar/index?city=${cityCode.value}`,
    }
});

// 分享到朋友圈
//#ifdef MP-WEIXIN
onShareTimeline(() => {
    return {
        title: "开盘日历",
        query: `city=${cityCode.value}`
    }
});
//#endif

// 页面加载
onLoad((options) => {
    //朋友圈进入小程序快照场景
    if(scene.value == 1154) return;
    
    let token = check_token();
    let time = new Date().getTime();
    if(!token) {
        token = '';
    }

    url.value = `https://image.srea.org.cn/house-market-xcx-webview/kai-pan-calendar/`;
    // url.value = `https://image.srea.org.cn/house-market-xcx-webview/kai-pan-calendar/?cityCode=${cityCode.value}&token=${token}&platform=${platform.value}&time=${time}#wechat_redirect`;
});
</script>
